<?php
/**
 * single.phtml
 *
 * @category    Madoqua
 * @package     Module
 * @subpackage  Feed
 */

/** zend feed */
require_once 'Zend/Feed.php';

$this->layout()->disableLayout();
//disable layouts

$config = $this->config();
//application config
if (count($this->comments)) {
    $latest = $this->comments->current()->posted;
    //publication date for the latest post
} else {
    $latest = time();
    //we just made it... now :x
}

$data = array(
    'title' => $this->post->title,
    'link' => $config->url . $this->urlPost($this->post),
    'description' => 'Post overview',
    'language' => $config->datetime->locale,
    'charset' => 'utf-8',
    'lastUpdate' => $latest,
    'generator' => 'Madoqua'
);
//feed config data

$data['entries'][] = array(
    'title' => 'post: ' . $this->post->title,
    'link' => $config->url . $this->urlPost($this->post),
    'guid' => $config->url . $this->urlPost($this->post),
    'description' => $this->post->intro,
    'lastUpdate' => $this->post->posted
);
//add post to the entries

foreach($this->comments as $comment) {
    
    $data['entries'][] = array(
        'title' => 'comment by ' . $comment->name,
        'link' => $config->url . $this->urlPost($this->post) . '#comment-' . $comment->id,
        'guid' => $config->url . $this->urlPost($this->post) . '#comment-' . $comment->id,
        'description' => $comment->content,
        'lastUpdate' => $comment->posted
    );
}
//post comments as feed entries

$feed = Zend_Feed::importArray($data, $this->type);

$header = 'Content-type: application/' . $this->type . '+xml; charset: utf-8';
Madoqua_Application::getFront()->getResponse()->setRawHeader($header);
//set proper header

echo $feed->saveXml();
//echo feed contents